import 'package:study_online/pages/messagePage/home_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/screenutil_init.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:im_flutter_sdk/im_flutter_sdk.dart';
import 'package:study_online/pages/chatPage/chat_page.dart';
import 'package:study_online/pages/homePage/views/HomeView.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemUiOverlayStyle uiStyle = SystemUiOverlayStyle.light;
  SystemChrome.setSystemUIOverlayStyle(uiStyle);
  EMPushConfig config = EMPushConfig()..enableAPNs('EaseIM_APNS_Product');
  var options = EMOptions(appKey: '1107210513231301#flutter');
  options.debugModel = true;
  options.pushConfig = config;
  EMClient.getInstance.init(options).then((value) => null);
  return runApp(EaseIMDemo());
}

class EaseIMDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);
    return ScreenUtilInit(
      designSize: Size(375, 667),
      builder: () {
        return MaterialApp(
          builder: (context, child) => FlutterSmartDialog(child: child),
          debugShowCheckedModeBanner: false,
          onGenerateRoute: onGenerateRoute,
          home: HomePage(),
        );
      },
    );
  }
}

Route<dynamic> onGenerateRoute(RouteSettings settings) {
  var routes = <String, WidgetBuilder>{
    '/home': (context) => HomePage(),
    'chatPage': (context) => ChatPage(
          (settings.arguments as List)[0],
          (settings.arguments as List)[1],
          (settings.arguments as List)[2],
        ),
  };
  WidgetBuilder builder = routes[settings.name];
  return MaterialPageRoute(builder: (ctx) => builder(ctx));
}
